package com.oig.sys.oauth.util;

import com.oig.common.util.SpringContextUtil;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;

import java.io.IOException;
import java.util.Map;

public class FreemarkerUtil {


    public static String parseTpl(String viewName, Map<String, Object> params) {
        Configuration cfg = SpringContextUtil.getBean(Configuration.class);
        String html = null;
        try {
            Template t =  cfg.getTemplate(viewName + ".ftl");
            html = FreeMarkerTemplateUtils.processTemplateIntoString(t, params);
        } catch (IOException | TemplateException e) {
            e.printStackTrace();
        }
        return html;
    }


    public static void main(String[] args) {

    }



}
